package com.dreamlin.gankio.mvvm.home.feature

import androidx.lifecycle.MutableLiveData
import com.dreamlin.gankio.base.model.BaseViewModel
import com.dreamlin.gankio.mvvm.home.GankEntity
import com.dreamlin.gankio.net.NetHelper
import com.dreamlin.gankio.net.RxHelper
import com.google.gson.annotations.SerializedName


/**
 * <p> Title: FeatureViewModel </p>
 * <p> Description: </p>
 * @author:  dreamlin
 * @date:    9/20/20
 * @version: V1.0.0
 * Created by dreamlin on 9/20/20.
 */
class FeatureRepository {
    val banners = MutableLiveData<List<BannerModel>>()
    val gankEntities = MutableLiveData<List<GankEntity>>()

    fun listBanners() {
        val subscribe = NetHelper.api.listBanners()
            .compose(RxHelper.applySchedulers(this))
            .compose(RxHelper.handleGlobalError(this))
            .subscribe({
                banners.value = it.data
            }, { it.printStackTrace() })
        addDisposable(subscribe)
    }

    fun listHots(count: Int) {
        val subscribe = NetHelper.api.listHots(count)
            .compose(RxHelper.applySchedulers(this))
            .compose(RxHelper.handleGlobalError(this))
            .subscribe({
                gankEntities.value = it.data
            }, { it.printStackTrace() })
        addDisposable(subscribe)
    }

}

data class BannerModel(
    @SerializedName("image")
    val image: String = "",
    @SerializedName("title")
    val title: String = "",
    @SerializedName("url")
    val url: String = ""
)